package com.songtech.uitest.aspects;

import com.songtech.uitest.components.ScreenShoter;
import com.songtech.uitest.entities.Indent;
import com.songtech.uitest.util.*;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class ModulePreAfterAspect {

    //打印日志前的缩进空格
    @Autowired
    private Space space;

    @Autowired
    private ScreenShoter screenShoter;

    @Autowired
    private SumUpHelper sumUpHelper;

    @Autowired
    private Indent indent;

    @Autowired
    private StepParser stepParser;


    private Logger logger = LoggerFactory.getLogger(ModulePreAfterAspect.class);


    //    @Pointcut("within(com.songtech.uitest.modules..*) ! execution(com.songtech.uitest.modules..*.set*(..))")
//    @Pointcut("within(com.songtech.uitest.modules..*)")
    @Pointcut("execution(public * com.songtech.uitest.module..*(..)) && !within(com.songtech.uitest.module.common..*)")
    public void moduleRelatedWorkPointCut(){ }



    //@Before("moduleRelatedWorkPointCut()")
    public void before(JoinPoint joinPoint) throws Exception{
        String step = joinPoint.getArgs()[0].toString();

        WebDriver driver = stepParser.parseDriver(step);
        AutoWait.setWebDriverWait(driver);

        System.out.println(joinPoint.getSignature().getName() + "方法初始化工作完毕");

    }

    //@AfterReturning(pointcut="moduleRelatedWorkPointCut()", returning = "returnVal")
    public void AfterReturning(JoinPoint joinPoint, Object returnVal){

        //记录单子的流程进行位置
        indent.setStepPosition(indent.getStepPosition() + 1);
        System.out.println(joinPoint.getSignature().getName() + "方法收尾工作完毕");

    }




}
